/**
 * Created by Administrator on 2018/2/5.
 */

myApp_.onPageInit('seller_community', function () {
    SELLER_COMMUNITY.do_get();
});


SELLER_COMMUNITY = {};
SELLER_COMMUNITY.__INIT__ = function () {
    mainView.router.load({
        url: "src/seller/community/community.html",
    });
}

SELLER_COMMUNITY.do_get = function () {
    SESSION.location(function (store) {
        var ad_code = store.ad_code ? store.ad_code : '';
        request_(
            url_('addons/execute/seller-App-community_list'),
            {
                "ad_code": ad_code
            },
            function (d) {
                if (d.code == 0) {
                    SELLER_COMMUNITY.fill_tpl({
                        community_list: d.data
                    });
                } else {
                    my_tips_(d.msg)
                }
            }
        );
    });
}

SELLER_COMMUNITY.fill_tpl = function (context) {
    $.tpl({
        url: 'src/seller/community/community_list_fill.html',
        elem: "#community_list_form",
        context: context,
        after: function (param) {
            console.log(param)
        }
    });
}


SELLER_COMMUNITY.do_request = function () {
    obj = document.getElementsByName("community");
    check_val = [];
    for (k in obj) {
        if (obj[k].checked)
            check_val.push(obj[k].value);
    }
    request_(
        url_('addons/execute/seller-App-seller_community_edit'),
        {
            community: check_val
        },
        function (d) {
            if (d.code == 0) {
                my_tips_(d.msg)
            } else {
                my_tips_(d.msg)
            }
        }
    );
}
